<template>
  <common-list>
    <common-search slot="search" @search="handleQuery" @reset="resetQuery">
      <el-form
        ref="queryForm"
        :inline="true"
        :model="queryParams"
        @submit.native.prevent
        label-width="65px"
      >
        <el-form-item label="报告名称" prop="reportName">
          <common-input
            :verify="false"
            v-model="queryParams.reportName"
            @enter="handleQuery"
            clearable
          />
        </el-form-item>
        <el-form-item label="审计模板" prop="auditType">
          <common-input
            :verify="false"
            v-model="queryParams.auditType"
            @enter="handleQuery"
            clearable
          />
        </el-form-item>
        <el-form-item label="生成时间" prop="time">
          <el-date-picker
            v-model="time"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
    </common-search>
    <common-table
      slot="content"
      v-loading="loading"
      :data="list"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="报告名称"
        align="left"
        prop="reportName"
        show-overflow-tooltip
      />
      <el-table-column
        label="审计模板"
        align="left"
        prop="auditType"
        show-overflow-tooltip
      />

      <el-table-column
        label="生成时间"
        align="left"
        prop="createTime"
        show-overflow-tooltip
      />

      <el-table-column label="操作" align="left" width="65" fixed="right">
        <template slot-scope="scope">
          <template>
            <el-button
              type="text"
              @click="handleShakeExport(scope.row)"
              :disabled="scope.row.isExportForShake"
              v-hasPermi="['system:auditreport:export']"
              >导出
            </el-button>
          </template>
        </template>
      </el-table-column>
    </common-table>

    <pagination
      slot="pagination"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <common-info-dialog
      :visible="isEditDialog"
      title="编辑评估维度"
      @cancel="isEditDialog = false"
    >
    </common-info-dialog>
  </common-list>
</template>

<script>
import {
  getPageList,
  queryAuditTypeList,
  queryInfo,
} from "@/api/apisecurity/auditReport/index";
import BaseList from "@/mixins/BaseList.vue";
export default {
  name: "index",
  mixins: [BaseList],
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        auditType: null,
        reportName: null,
      },
      auditType: [],
      total: 0,
      isEditDialog: false,
      list: [],
      loading: false,
      time: [],
    };
  },
  methods: {
    handleExport(row) {
      return new Promise((resolve, reject) => {
        this.download(
          "/system/auditReport/export",
          {
            id: row.id,
            type: "xlsx",
          },
          `${row.reportName}.xlsx`
        ).finally(() => {
          resolve();
        });
      });
    },
    handleInfo(row) {
      this.isEditDialog = true;
      queryInfo({ id: row.id }).then((res) => {});
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.queryParams = this.$options.data().queryParams;
      this.time = [];
    },
    getList() {
      this.loading = true;
      let params = {
        ...this.queryParams,
        beginTime: this.time && this.time.length === 0 ? null : this.time[0],
        endTime: this.time && this.time.length === 0 ? null : this.time[1],
      };
      getPageList(params)
        .then((res) => {
          if (res && res.code === 200) {
            this.list = res.rows.reduce((r, c) => {
              r.push({ ...c, isExportForShake: false });
              return r;
            }, []);
            this.total = res.total;
            this.handleListTips(res);
          } else {
            this.list = [];
            this.total = 0;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    auditTypeList() {
      queryAuditTypeList().then((res) => {
        if (res && res.code) {
          this.auditType = res.data;
        } else {
          this.auditType = [];
        }
      });
    },
  },

  created() {
    this.getList();
    this.auditTypeList();
  },
};
</script>
<style lang="scss" scoped></style>
